import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import { cancelAll } from '@/utils/request'

Vue.use(VueRouter) // 注册：调用VueRouter内的一个方法

const routes = [
  {
    path: '/home/:xxx?', // ?代表xxx参数可传可不传，不加?一定要传
    name: 'home',
    // component: HomeView,
    components: {
      default: HomeView,
      xxx: () => import('@/components/HmTabbar.vue')
    },
    meta: { title: '首页' }

    // redirect:''
    // alias: '/home'
  },
  {
    path: '/about',
    name: 'about',
    beforeEnter: (to, from, next) => {
      // ...
      console.log('beforeEnter')
      next()
    },
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () =>
      import(/* webpackChunkName: "about" */ '../views/AboutView.vue'),
    children: [
      // {
      //   path: 'tabbar', //  tabbar /about/tabbar   /tabbar   /tabbar   ''  /about
      //   name: 'tabbar'
      // }
    ]
  }
]

const router = new VueRouter({
  routes
})
router.beforeEach((to, from, next) => {
  cancelAll()
  console.log('beforeEach')
  next()
})
router.beforeResolve((to, from, next) => {
  console.log('beforeResolve')
  next()
})
router.afterEach((to, from) => {
  console.log('afterEach')
})

export default router
